<%@page contentType="text/html; charset=UTF-8" %>
<%@include file="/WEB-INF/jsp/init.jsp"%>

<script type="text/javascript">
    jQuery(function ($) {
        $("#isCreateTransaction").click(function () {
            if (this.checked) {
                $("#create-transaction2").show(200);
            } else {
                $("#create-transaction2").hide(200);
            }
        });

        $.get('/clue/getById?id=${param.id}', function (data) {
            $("#companyName").text(data.company);
            $("#contactName").text(data.fullName);
            $(":input[name=name]").val(data.company + "-");
        });

        $("#convertBtn").click(function () {

            if(!confirm("确定转换吗？")) {
                return;
            }

            // 获取交易表单数据
            let data = $("#tranForm").serializeObject();
            data.clueId = "${param.id}";
            data.createTran = $("#isCreateTransaction").prop("checked");

            $.post('/clue/convert', data).done(function (data) {
                if (data.success) {
                    loadMain('/clue/index.html');
                }
            });
        });
    });
</script>

<!-- 关联市场活动的模态窗口 -->
<%@include file="/WEB-INF/jsp/inc/dialog/bindActivity.jsp"%>

<!-- 返回按钮 -->
<div class="page-header">
    <h3>
        <button class="btn btn-default" onclick="back();">
            <span class="glyphicon glyphicon-arrow-left"></span> 返回
        </button>
        <button class="btn btn-primary" id="convertBtn">
            <span class="glyphicon glyphicon-retweet"></span> 转换
        </button>
    </h3>
</div>

<div id="create-customer" style="height:30px;">
    <b>新建客户：</b><b id="companyName"></b>
</div>
<div id="create-contact" style="height:30px;">
    <b>新建联系人：</b><b id="contactName"></b>
</div>
<hr>
<div id="create-transaction1">
    <input type="checkbox" id="isCreateTransaction"/>
    <b>为客户创建交易</b>
</div>

<div id="create-transaction2" style="display: none;margin-top:20px;">
    <form id="tranForm" class="form-horizontal" role="form" style="width: 800px;">
        <input type="hidden" name="activityId" id="activityId" />

        <div class="form-group">
            <label for="amountOfMoney" class="col-sm-2 control-label">金额</label>
            <div class="col-sm-10">
                <input name="amountOfMoney" type="text" class="form-control" id="amountOfMoney">
            </div>
        </div>
        <div class="form-group">
            <label for="tradeName" class="col-sm-2 control-label">交易名称</label>
            <div class="col-sm-10">
                <input name="name" type="text" class="form-control" id="tradeName" value="百度集团-">
            </div>
        </div>
        <div class="form-group">
            <label for="expectedClosingDate" class="col-sm-2 control-label">预计成交日期</label>
            <div class="col-sm-10">
                <input name="expectedClosingDate" date type="text" class="form-control" id="expectedClosingDate">
            </div>
        </div>
        <div class="form-group">
            <label for="stage" class="col-sm-2 control-label">阶段</label>
            <div class="col-sm-10">
                <select name="stage" options="stage" id="stage" class="form-control">
                    <option></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="activity" class="col-sm-2 control-label">市场活动源
                <a href="###" data-toggle="modal" data-target="#bindActivityModal" style="text-decoration: none;">
                    <span class="glyphicon glyphicon-search"></span>
                </a>
            </label>
            <div class="col-sm-10">
                <input id="activityName" type="text" class="form-control" id="activity" placeholder="点击上面搜索" readonly>
            </div>
        </div>
    </form>
</div>
